home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 17
/
CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso
/
CUCD
/
Magazine
/
C_Tutorial
/
Part-2
/
mouse3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-01
|
3KB
|
101 lines
#include<exec/libraries.h>
#include<intuition/intuition.h>
#include<utility/tagitem.h>
#include<graphics/text.h>
#include<graphics/rastport.h>
#include<string.h>
#include<clib/exec_protos.h>
#include<clib/graphics_protos.h>
#include<clib/intuition_protos.h>
struct Library* GfxBase;
struct Library* IntuitionBase;
/* Need to give a prototype for our message handling function */
void handleIDCMP(struct Window*);
void main()
{
/* Open libraries... */
if(GfxBase = OpenLibrary("graphics.library",36))
{
if(IntuitionBase = OpenLibrary("intuition.library",36))
{
/* Open our window */
struct Window* win;
if(win = OpenWindowTags(NULL,
WA_Left, 20,
WA_Top, 20,
WA_Width, 200,
WA_Height, 100,
WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_REPORTMOUSE | WFLG_GIMMEZEROZERO,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE,
TAG_DONE, 0))
{
/* If window opened, handle its IDCMP messages */
handleIDCMP(win);
CloseWindow(win);
}
CloseLibrary(IntuitionBase);
}
CloseLibrary(GfxBase);
}
}
/* Our message handling code */
void handleIDCMP(struct Window* win)
{
char* text = "Hello World!";
int going = TRUE;
int drawing = FALSE;
UBYTE pen = 1;
SetDrMd(win->RPort, JAM1);
/* Loop, waiting for messages, until the close gadget clicked */
while(going)
{
struct IntuiMessage* intuimsg;
/* Wait for messages to arrive */
WaitPort(win->UserPort);
/* Messages have arrived: loop through all of them */
while(intuimsg = (struct IntuiMessage*)GetMsg(win->UserPort))
{
/* Act on this message... */
switch(intuimsg->Class)
{
case IDCMP_MOUSEBUTTONS:
switch(intuimsg->Code)
{
case SELECTDOWN:
drawing = TRUE;
break;
case SELECTUP:
drawing = FALSE;
break;
}
/* Omit the break to draw on click, too */
break;
case IDCMP_MOUSEMOVE:
if(drawing)
{
/* Try changing colour using something like this: */
/* SetAPen(win->RPort, pen++); */
/* Or this: */
SetAPen(win->RPort, (UBYTE)(intuimsg->MouseY / 8));
/* Or something of your own invention... */
/* Note: have to get GZZ mouse coords from the window */
Move(win->RPort, win->GZZMouseX, win->GZZMouseY);
Text(win->RPort, text, strlen(text));
}
break;
case IDCMP_CLOSEWINDOW:
going = FALSE;
break;
}
/* Reply when finished with message */
ReplyMsg((struct Message*)intuimsg);
}
}
}